//
//  main.c
//  smart_garbage_case
//
//  Created by fukai,caihui on 2018/11.
//  Copyright © 2018年 Cyber01. All rights reserved.
//

#include "stm32f10x.h"
#include "oled.h"
#include "pwm.h"
#include "adc.h"
#include "key.h"
#include "timer_interrupt.h"
#include "action_ctrl.h"
#include "user_interface.h"
#include "path_planning.h"


//主循环状态机
typedef enum
{
	GET_INFO = 0,	//信息采集
	ANALYSE_INFO,
	SHOW_INFO,
	SEND_INFO,
}MainStatusNode;

MainStatusNode MainStatus = GET_INFO;

//硬件初始化函数
void BoardInit(void)
{
	// 设置中断优先级分组2
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	
	DelayInit();	//延时函数初始化
	KeyInit();
	OledInit();
	AdcInit();
	SystemPwmInit();
	SystemTimIntInit(30-1,7199);//3ms一次中断  72000000/7200=10kHZ 
}


int main()
{
	BoardInit();
	
	while(1)
	{
		switch(MainStatus)
		{
			case GET_INFO:
				GetAdcUse();	//获取红外AD值
				if(AdcValue.front_infrared_ad>20)
				{
					ActionCtrl.ServoCtrl.ServoAcFlag = COVER_OPEN;
					ActionCtrl.MotorCtrl.MotorACFlag = CAR_STOP;
				}
				else
				{
					ActionCtrl.ServoCtrl.ServoAcFlag = COVER_CLOSE;
				}
				MainStatus = ANALYSE_INFO;
				break;
			
			case ANALYSE_INFO:
				CarPathPlanning();
				MainStatus = SHOW_INFO;
				break;
			
			case SHOW_INFO:
				UserInterface();
				MainStatus = SEND_INFO;
				break;
			
			case SEND_INFO:
				MainStatus = GET_INFO;
				break;
		}
	}
} 











